<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        制作件入库单
    </h1>
</section>
<section class="content">
    <div id="printArea" style=" display: none;">
        <div style="padding-bottom: 10px;text-align: center;vertical-align: middle;">
            <div style="font-size: 20px;vertical-align: middle;display: inline-block;font-weight: bold;">机械工程部入库单</div>
        </div>
        <table style="font-size:12px;width: 100%;line-height: 20px;">
            <tr>
                <td width="25%">单据编号：<label id="odrCodePrint" style="font-weight: normal"></label></td>
                <td width="20%">库位：<label id="odrWhiIdPrint" style="font-weight: normal"></label></td>
                <td width="25%">往来部门：<label id="odrDeptPrint" style="font-weight: normal"></label></td>
                <td width="30%">经手人：<label id="odrCheckerPrint" style="font-weight: normal"></label></td>
            </tr>
            <tr>
                <td colspan="2">说明：<label id="odrSummaryPrint" style="font-weight: normal"></label></td>
                <td>制单人：<label id="odrTakePersonPrint" style="font-weight: normal"></label></td>
                <td>联系方式：<label id="odrServicePersonPrint" style="font-weight: normal"></label></td>
            </tr>
        </table>
        <div id="table-box">
        </div>
        <!--<div style="margin-top: 10px">
            领料人签字：
        </div>-->
    </div>
    <form id="inbillForm" th:action="@{/half/halWarManage/finishWar/create}" method="post" class="form-inline"
          role="form"
          enctype="multipart/form-data">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        <div class="row">
                            <div class="form-group">
                                <label>单据编号</label>
                                <input type="text" class="form-control" name="" placeholder=""
                                       readonly="readonly"/>
                            </div>
                            <div class="form-group">
                                <label>往来部门</label>
                                <select id="odrDept" name="odrDept" class="form-control select2">
                                    <option value="">请选择</option>
                                    <option th:each="type:${dept}" th:value="${type.depId}"
                                            th:text="${type.depName}"></option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>经手人</label>
                                <input id="odrChecker" type="text" class="form-control" name="" placeholder=""
                                       autocomplete="off"/>
                            </div>
                            <div class="form-group">
                                <label>联系方式</label>
                                <input id="odrServicePerson" type="text" class="form-control" name="" placeholder=""
                                       autocomplete="off"/>
                            </div>
                            <div class="form-group">
                                <label>说明</label>
                                <input id="odrSummary" type="text" class="form-control" name="" placeholder=""
                                       autocomplete="off"/>
                            </div>
                            <div class="form-group">
                                <label>单据类型</label>
                                <select id="odrOutType" class="form-control" name="odrOutType">
                                    <option value="8">生产入库</option>
                                    <option value="2">返料入库</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>库位</label>
                                <select id="odaWhiId" name="odaWhiId select" class="form-control">
                                    <!--<option value="">请选择</option>-->
                                    <option th:each="type:${warInfo}" th:value="${type.whiId}"
                                            th:text="${type.whiName}"></option>
                                </select>
                            </div>

                            <div class="form-group pull-right" style="line-height: 34px;">
                                <a th:href="@{/file/制作件入库单据导入模板.xlsx}">模版下载</a>
                            </div>
                        </div>
                        <div class="row">
                            <div id="hot"></div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="row">
                            <div class="col-md-2">
                                <label>制单人：</label><label th:text="${userName}"></label>
                            </div>
                            <div class="col-md-6">
                                <label></label>
                            </div>
                            <div class="col-md-4">
                                <div class="col-md-2 col-md-offset-7">
                                    <!--<button type="button" class="btn btn-info file-contract btn-file">打印</button>-->
                                </div>
                                <div class="col-md-2">
                                    <button type="button" id="btn-saveInBill"
                                            class="btn btn-info file-contract btn-file" shiro:hasPermission="halwar:halmakeinwar:edit">保存
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
<div th:include="include :: footer"></div>
<script th:src="@{/js/jquery.PrintArea.js}"></script>
<script th:inline="javascript">

    $(function () {
        //仓库数组
        var warehouseInfoArray;

        js.ajax({
            url: ctx + 'basic/half/warehouseInfo',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {},
            async: false,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    warehouseInfoArray = new Array();

                    for (var i = 0; i < result.data.rows.length; i++) {
                        warehouseInfoArray.push(result.data.rows[i].whiName);
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        });
        var process = function (data) {
            if ($("#odaWhiId").val() == "") {
                js.modal.warning("请选择仓库！");
                $("#odaWhiId").focus();
                return;
            }
            if ($.isEmptyObject(data.insertData)) {
                js.modal.warning("入库明细不允许为空！");
                return;
            }

            js.post({
                url: ctx + "half/halWarManage/finishWar/create",
                data: JSON.stringify(data),
                contentType: "application/json",
                success: function (result) {
                    if (result.data.list[0] == "单据保存成功！") {
                        js.hot.loadData([]);
                        $("#odrChecker").val("");
                        $("#odrServicePerson").val("");
                        $("#odrSummary").val("");
                        $("#odrDept").val('').trigger("change");
                        $("#odaWhiId").val("");
                        js.modal.success("保存成功！")
                        /*js.modal.confirm("单据保存成功，是否需要打印？", function () {
                            var num = result.data.id;
                            js.post({
                                url: ctx + "half/halWarManage/finishWar/printList",
                                data: {
                                    id: num
                                },
                                contentType: "application/x-www-form-urlencoded",
                                success: function (data) {

                                    $("#odrCodePrint").text(data.data["odrCode"]);
                                    $("#odrWhiIdPrint").text(data.data["odaWhiIdName"]);
                                    $("#odrDeptPrint").text(data.data["odrDept"]);
                                    $("#odrCheckerPrint").text(data.data["odrChecker"]);
                                    $("#odrSummaryPrint").text(data.data["odrSummary"]);
                                    $("#odrTakePersonPrint").text(data.data["odrTakePerson"]);
                                    $("#odrServicePersonPrint").text(data.data["odrServicePerson"]);

                                    // 绑定打印明细数据
                                    printInBillDetail(num);
                                    //location.reload();
                                }
                            });
                        });*/

                    } else {
                        js.modal.warning(result.data.list);
                    }

                }
            });
        }

        // 绑定打印明细数据
        function printInBillDetail(id) {

            $("#printArea").show();
            js.post({
                url: ctx + "half/halWarManage/finishWar/printDetailList",
                data: {
                    id: id
                },
                contentType: "application/x-www-form-urlencoded",
                success: function (data) {
                    var printList = data.data;
                    // 添加dataTable表头
                    $("#table-box").empty();
                    $("#table-box").append('<table id="inBillTable"\n' +
                        '               style="font-size: 12px;text-align: center;border-right:1px solid;border-bottom:1px solid; border-collapse: collapse;"\n' +
                        '               width="100%"\n' +
                        '               cellspacing="0" cellpadding="1">\n' +
                        '        </table>');
                    $("#inBillTable").append('<THEAD style="display:table-header-group;">\n' +
                        '<TR><td style="border-left: 1px solid;border-top: 1px solid;">序号</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">物料描述</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">图号</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">数量</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">单位</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">项目编号</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">项目名称</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">部分名称</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">是否成品</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">存放状态</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">箱号</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">装箱日期</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">存放位置</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">记账日期</td>' +
                        '<td style="border-left: 1px solid;border-top: 1px solid;">备注</td></TR>\n ' +
                        '</THEAD> ');
                    $("#inBillTable").append('<tbody id="myTb"> </tbody>');
                    // 循环绑定dataTable行数据
                    var rowIndex;
                    var odaMatNamePrint;
                    var odaDrawingCodePrint;
                    var odaNumPrint;
                    var odaUnitPrint;
                    var odaProCodePrint;
                    var odaProNamePrint;
                    var odaPartPrint;
                    var odaIfFinishedProductPrint;
                    var odaMakingPiecesStatusPrint;
                    var odaCaseNoPrint;
                    var odaBoxingDatePrint;
                    var odaPositionPrint;
                    var odaStorageDatePrint;
                    var odaRemarkPrint;

                    var newRow;

                    for (i = 0; i < printList.length; i++) {
                        rowIndex = printList[i]["rowIndex"];
                        odaMatNamePrint = printList[i]["odaMatName"];
                        odaDrawingCodePrint = printList[i]["odaDrawingCode"];
                        odaNumPrint = printList[i]["odaNum"];
                        odaUnitPrint = printList[i]["odaUnit"];
                        odaProCodePrint = printList[i]["odaProCode"];
                        odaProNamePrint = printList[i]["odaProName"];
                        odaPartPrint = printList[i]["odaPart"];
                        odaIfFinishedProductPrint = printList[i]["odaIfFinishedProductName"];
                        odaMakingPiecesStatusPrint = printList[i]["odaMakingPiecesStatus"];
                        odaCaseNoPrint = printList[i]["odaCaseNo"];
                        odaBoxingDatePrint = printList[i]["odaBoxingDate"];
                        odaPositionPrint = printList[i]["odaPosition"];
                        odaStorageDatePrint = printList[i]["odaStorageDate"];
                        odaRemarkPrint = printList[i]["odaRemark"];

                        newRow = "<tr><td style='border-left:1px solid;border-top:1px solid'>" + rowIndex + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaMatNamePrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaDrawingCodePrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaNumPrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaUnitPrint + "</td> \n" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaProCodePrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaProNamePrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaPartPrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaIfFinishedProductPrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaMakingPiecesStatusPrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaCaseNoPrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaBoxingDatePrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaPositionPrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaStorageDatePrint + "</td>" +
                            "<td style='border-left:1px solid;border-top:1px solid'>" + odaRemarkPrint + "</td></tr>";
                        $("#myTb").append(newRow);

                    }
                    $("#printArea").printArea();
                    $("#printArea").hide();
                }
            });
        }

        js.hot.init({
            element: document.getElementById('hot'),
            data: {},
            formData: ["odrDept", "odrChecker", "odrServicePerson", "odrSummary", "odrOutType","odaWhiId"],
            colHeaders: ['ID', '物料描述', '图号', '数量', '单位', '项目编号', '项目名称', '部分名称','合同编号', '是否成品', '存放状态', '箱号', '装箱日期', '区位', '在库类型', '记账日期', '备注'],
            fieldName: ['odaId', 'odaMatName', 'odaDrawingCode', 'odaAvaNum', 'odaUnit', 'odaProCode', 'odaProName', 'odaPart','contractNo', 'odaIfFinishedProductName', 'odaMakingPiecesStatus', 'odaCaseNo', 'odaBoxingDate',  'odaPosition', 'odaStockTypeName', 'odaStorageDate', 'odaRemark'],
            height: 640,
            correctFormat: true,
            minSpareRows: 2000,
            hiddenColumns: {
                columns: [0],
                indicators: true
            },
            callBack: process,
            saveButtonId: $("#btn-saveInBill"),
            columns: [
                {
                    data: 'odaId',
                    type: 'numeric',
                    width: 40
                },
                {
                    data: 'odaMatName',//物料描述
                    type: 'text'
                },
                {
                    data: 'odaDrawingCode',//图号
                    type: 'text'
                },
                {
                    data: 'odaAvaNum',//数量
                    type: 'numeric'
                },
                {
                    data: 'odaUnit',//单位
                    type: 'text'
                },
                {
                    data: 'odaProCode',//项目编号
                    type: 'text'
                },
                {
                    data: 'odaProName',//项目名称
                    type: 'text'
                },
                {
                    data: 'odaPart',//部位
                    type: 'text'
                },
                {
                    data: 'contractNo',//合同编号
                    type: 'text'
                },
                {
                    data: 'odaIfFinishedProductName',//是否成品
                    type: 'dropdown',
                    source: ['是', '否']
                },
                {
                    data: 'odaMakingPiecesStatus',//存放状态
                    type: 'dropdown',
                    source: ['待装配', '待发货', '待机加', '待外协','临时存放']
                },
                {
                    data: 'odaCaseNo',//箱号
                    type: 'text'
                },
                {
                    data: 'odaBoxingDate',//装箱日期
                    type: 'date',
                    dateFormat: 'YYYY/MM/DD',
                    correctFormat: true
                },
                {
                    data: 'odaPosition',//区位
                    type: 'text'
                },
                {
                    data: 'odaStockTypeName',//在库类型
                    type: 'dropdown',
                    source: ['项目在库', '库存在库']
                },
                {
                    data: 'odaStorageDate',//入库时间
                    type: 'date',
                    dateFormat: 'YYYY/MM/DD',
                    correctFormat: true
                },
                {
                    data: 'odaRemark',//备注
                    type: 'text'
                }
            ]
        });
    });

</script>


</body>
</html>